using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using popLib;
using System.IO;
using System.Threading;

namespace SubtitleHandler
{
    public partial class Form1 : Form
    {
        public Form1(string srcFile)
        {
            InitializeComponent();

            FormLib.setTransparentForm(this, 255, FormBackground.VistaBlueContainer, new TransparentFormOption());
            
            FormLib.ExecuteDragAndDrop func = delegate(Control control, string[] files) {
                if (Path.GetExtension(files[0]).ToLower() != ".srt" && !FormLib.confirm("Drag and drop file is not supported!!!\r\nDo you want to continue?"))
                    return;

                des.Text = src.Text = files[0];
                src.Select(src.Text.Length, 0);
                des.Select(des.Text.Length, 0);
            };

            FormLib.dragAndDrop(this, func);
            FormLib.dragAndDrop(src, func);
            FormLib.dragAndDrop(des, func);
            FormLib.dragAndDrop(textBox1, func);


            src.Text = srcFile;
            des.Text = srcFile;
        }

        void Button1Click(object sender, EventArgs e)
        {
        	ReturnSet rs = FormLib.openFile("SRT files(*.srt)|*.srt|All files(*.*)|*.*");            	
        	if (rs.Success) src.Text = rs.Result.ToString();
        }

        void Button2Click(object sender, EventArgs e)
        {
            string file = FormLib.saveFile("SRT files(*.srt)|*.srt|All files(*.*)|*.*");
            if (file != null) des.Text = file;
        }

        void Button3Click(object sender, EventArgs e)
        {
            if (!File.Exists(src.Text)) return;
            if (!StringLib.isValid(des.Text)) return;
            if (sec.Value == 0 && mili.Value == 0) return;

            Program.process(src.Text, des.Text, string.Format("{0}0:0:{1},{2}", (sec.Value < 0 || mili.Value < 0) ? "-" : ""
                                                               , Math.Abs(sec.Value), Math.Abs(mili.Value)));
            FormLib.alert("Done");
        }
    }
}
